

<div class="mws-panel grid_8 quizzes form">

    <div class="mws-panel-header">
        <span class="mws-i-24 i-table-1"><?php echo __('Admin Add Quiz'); ?></span>
    </div>
    <div class="quistion-list" style="display: none;">

        <?php // <editor-fold defaultstate="collapsed"  desc="Multiple"> ?>
        <div class="multiple"  >
            <div class="q-header" >Multiple</div>
            <div class="mws-form-inline">
                <?php
                echo $this->Form->create('Question', array("class" => "mws-form", "type" => "file"));
                echo $this->Form->input('id');
                echo $this->Form->input('subject_id', array("type" => "hidden"));
                echo $this->Form->input('body', array("div" => "mws-form-row", "type" => "textarea", "class" => "", "between" => '<div class="mws-form-item large">')) . "<div class='q-container'>";
                echo $this->Form->input('display_order', array("div" => "e_right", "after" => '<span class="add-on">' . __("Display Order") . '</span>', "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div></div></div>";
                echo $this->Form->input('question_type', array("type" => "hidden", "value" => "multiple"));
                echo "<div class='q-choices many-container'>
                    <ul class='many'>";
                echo "<li><span class='remove-option mws-ic-16 ic-cross' onclick='remove_option(this)'></span>";
                echo $this->Form->input('QuestionChoice.0.display_order', array("div" => "e_right", "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.body', array("div" => "e_right", "class" => " span3", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.points', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";

                echo '<div class="clear"></div></li>';
                echo '</ul><div class="clear"></div><a class="add-option mws-ic-16 ic-add add" >Add onther option</a></div>'
                ?>

                <div class="mws-button-row">
                    <input type="submit" class="mws-button orange mws-i-24 i-check large" value="<?php echo __('Submit'); ?>">
                </div>
                <?php echo $this->Form->end(); ?>
            </div>

            <div class="clear"> </div>
        </div>
        <?php //</editor-fold> ?>

        <?php // <editor-fold defaultstate="collapsed"  desc="One choice"> ?>
        <div class="one-choice"  >
            <div class="q-header" >One choice</div>
            <div class="mws-form-inline">
                <?php
                echo $this->Form->create('Question', array("class" => "mws-form", "type" => "file"));

                echo $this->Form->input('id');
                echo $this->Form->input('body', array("div" => "mws-form-row", "type" => "textarea", "class" => "", "between" => '<div class="mws-form-item large">')) . "<div class='q-container'>";
                echo $this->Form->input('display_order', array("div" => "e_right", "after" => '<span class="add-on">' . __("Display Order") . '</span>', "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div></div></div>";
                echo $this->Form->input('question_type', array("type" => "hidden", "value" => "one-choice"));
                echo " <div class='q-choices many-container'>
                    <ul class='many'>";
                echo "<li><span class='remove-option mws-ic-16 ic-cross' onclick='remove_option(this)'></span>";
                echo $this->Form->input('QuestionChoice.0.display_order', array("div" => "e_right", "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.body', array("div" => "e_right", "class" => " span3", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.points', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo '<div class="clear"></div></li>';
                echo '</ul><div class="clear"></div><a class="add-option mws-ic-16 ic-add add" >Add onther option</a></div>'
                ?>

                <div class="mws-button-row">
                    <input type="submit" class="mws-button orange mws-i-24 i-check large" value="<?php echo __('Submit'); ?>">
                </div>
                <?php echo $this->Form->end(); ?>

            </div>
            <div class="clear"> </div>
        </div>
        <?php //</editor-fold> ?>

        <?php // <editor-fold defaultstate="collapsed"  desc="True & False"> ?>
        <div class="true-false"  >
            <div class="q-header" >True & False</div>
            <div class="mws-form-inline">
                <?php
                echo $this->Form->create('Question', array("class" => "mws-form", "type" => "file"));

                echo $this->Form->input('id');
                echo $this->Form->input('body', array("div" => "mws-form-row", "type" => "textarea", "class" => "", "between" => '<div class="mws-form-item large">')) . "<div class='q-container'>";
                echo $this->Form->input('display_order', array("div" => "e_right", "after" => '<span class="add-on">' . __("Display Order") . '</span>', "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div></div></div>";
                echo $this->Form->input('question_type', array("type" => "hidden", "value" => "true-false"));
                echo " <div class='q-choices many-container'>
                    <ul class='many'>";
                echo "<li>";
                echo $this->Form->input('QuestionChoice.0.display_order', array("div" => "e_right", "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.body', array("div" => "e_right", "class" => " span3", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                // echo $this->Form->input('QuestionChoice.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.points', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo '<div class="clear"></div></li>';
                echo "<li>";
                echo $this->Form->input('QuestionChoice.1.display_order', array("div" => "e_right", "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.1.body', array("div" => "e_right", "class" => " span3", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                // echo $this->Form->input('QuestionChoice.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.1.points', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo '<div class="clear"></div></li>';

                echo '</ul><div class="clear"></div></div>'
                ?>

                <div class="mws-button-row">
                    <input type="submit" class="mws-button orange mws-i-24 i-check large" value="<?php echo __('Submit'); ?>">
                </div>
                <?php echo $this->Form->end(); ?>

            </div>
            <div class="clear"> </div>
        </div>
        <?php //</editor-fold> ?>

        <?php // <editor-fold defaultstate="collapsed"  desc="Listen"> ?>
        <div class="listen"  >
            <div class="q-header" >Listen</div>
            <div class="mws-form-inline">
                <?php
                echo $this->Form->create('Question', array("class" => "mws-form", "type" => "file"));
                echo $this->Form->input('id');
                echo $this->Form->input('body', array("div" => "e_right input-file-width", "file_type" => "sound", "type" => "file", "class" => "", "between" => '<div class="q-container">', "label" => false)) . "</div><div class='q-container'>";
                echo $this->Form->input('display_order', array("div" => "e_right", "after" => '<span class="add-on">' . __("Display Order") . '</span>', "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div></div>";
                echo '<div class="clear"></div>';
                echo $this->Form->input('question_type', array("type" => "hidden", "value" => "listen"));
                echo "<div class='q-choices many-container'><ul class='many'>";
                echo "<li><span class='remove-option mws-ic-16 ic-cross' onclick='remove_option(this)'></span>";
                echo $this->Form->input('QuestionChoice.0.display_order', array("div" => "e_right", "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.body', array("div" => "e_right", "class" => " span3", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.points', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo '<div class="clear"></div></li>';
                echo '</ul><div class="clear"></div><a class="add-option mws-ic-16 ic-add add" >Add onther option</a></div>'
                ?>

                <div class="mws-button-row">
                    <input type="submit" class="mws-button orange mws-i-24 i-check large" value="<?php echo __('Submit'); ?>">
                </div>
                <?php echo $this->Form->end(); ?>

            </div>
            <div class="clear"> </div>
        </div>
        <?php //</editor-fold> ?>

        <?php // <editor-fold defaultstate="collapsed"  desc="Matches"> ?>
        <div class="matches">
            <div class="q-header" >Matches</div>
            <div class="mws-form-inline">
                <?php
                echo $this->Form->create('Question', array("class" => "mws-form", "type" => "file"));

                echo $this->Form->input('id');
                echo $this->Form->input('body', array("div" => "mws-form-row", "type" => "textarea", "class" => "", "between" => '<div class="mws-form-item large">')) . "<div class='q-container'>";
                echo $this->Form->input('display_order', array("div" => "e_right", "after" => '<span class="add-on">' . __("Display Order") . '</span>', "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div></div></div>";
                echo $this->Form->input('question_type', array("type" => "hidden", "value" => "matches"));
                echo "<div class='q-choices many-container'>
                    <ul class='many'>";
                echo "<li><span class='remove-option mws-ic-16 ic-cross' onclick='remove_option(this)'></span>";
                echo $this->Form->input('QuestionChoice.0.display_order', array("div" => "e_right", "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.body', array("div" => "e_right", "class" => " span2", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionMatch.0.display_order', array("div" => "e_right", "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionMatch.0.body', array("div" => "e_right", "class" => " span2", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionMatch.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.points', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo '<div class="clear"></div></li>';

                echo '</ul><div class="clear"></div><a class="add-option mws-ic-16 ic-add add" >Add onther option</a></div>'
                ?>

                <div class="mws-button-row">
                    <input type="submit" class="mws-button orange mws-i-24 i-check large" value="<?php echo __('Submit'); ?>">
                </div>
                <?php echo $this->Form->end(); ?>

            </div>
            <div class="clear"> </div>
        </div>
        <?php //</editor-fold> ?>

        <?php // <editor-fold defaultstate="collapsed"  desc="Order"> ?>
        <div class="q-order"  >
            <div class="q-header" >Order</div>
            <div class="mws-form-inline">
                <?php
                echo $this->Form->create('Question', array("class" => "mws-form", "type" => "file"));

                echo $this->Form->input('id');
                echo $this->Form->input('body', array("div" => "mws-form-row", "type" => "textarea", "class" => "", "between" => '<div class="mws-form-item large">')) . "<div class='q-container'>";
                echo $this->Form->input('display_order', array("div" => "e_right", "after" => '<span class="add-on">' . __("Display Order") . '</span>', "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div></div></div>";
                echo $this->Form->input('question_type', array("type" => "hidden", "value" => "q-order"));
                echo "
                    <div class='q-choices many-container'>
                    <ul class='many'>";

                echo "<li><span class='remove-option mws-ic-16 ic-cross' onclick='remove_option(this)'></span>";
                echo $this->Form->input('QuestionChoice.0.display_order', array("div" => "e_right", "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.body', array("div" => "e_right", "class" => " span3", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.c_order', array("div" => "e_right", "after" => '<span class="add-on">' . __("Order") . '</span>', "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.points', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo '<div class="clear"></div></li>';

                echo '</ul><div class="clear"></div><a class="add-option mws-ic-16 ic-add add" >Add onther option</a></div>'
                ?>

                <div class="mws-button-row">
                    <input type="submit" class="mws-button orange mws-i-24 i-check large" value="<?php echo __('Submit'); ?>">
                </div>
                <?php echo $this->Form->end(); ?>

            </div>
            <div class="clear"> </div>
        </div>
        <?php //</editor-fold> ?>

        <?php // <editor-fold defaultstate="collapsed"  desc="Classification"> ?>
        <div class="classification"  >
            <div class="q-header" >Classification</div>
            <div class="mws-form-inline">
                <?php
                echo $this->Form->create('Question', array("class" => "mws-form", "type" => "file"));

                echo $this->Form->input('id');
                echo $this->Form->input('body', array("div" => "mws-form-row", "type" => "textarea", "class" => "", "between" => '<div class="mws-form-item large">')) . "<div class='q-container'>";
                echo $this->Form->input('display_order', array("div" => "e_right", "after" => '<span class="add-on">' . __("Display Order") . '</span>', "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div></div></div>";

                echo $this->Form->input('question_type', array("type" => "hidden", "value" => "classification"));
                echo "
                    <div class='q-choices many-container'>
                    <ul class='many'>";

                echo "<li><span class='remove-option mws-ic-16 ic-cross' onclick='remove_option(this)'></span>";
                echo $this->Form->input('QuestionChoice.0.display_order', array("div" => "e_right", "class" => " span1 s1", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.body', array("div" => "e_right", "class" => " span3", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.points', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo '<div class="clear"></div></li>';

                echo '</ul><div class="clear"></div><a class="add-option mws-ic-16 ic-add add" >Add onther option</a></div>'
                ?>

                <div class="mws-button-row">
                    <input type="submit" class="mws-button orange mws-i-24 i-check large" value="<?php echo __('Submit'); ?>">
                </div>
                <?php echo $this->Form->end(); ?>

            </div>
            <div class="clear"> </div>
        </div>
        <?php //</editor-fold> ?>


    </div>
    <div class="mws-panel-body question_container" id="sortable" style="min-height: 100px;">
        <div class="multiple"  >
            <div class="q-header" >Title</div>
            <div class="mws-form-inline">
                <?php echo $this->Form->create('Question', array("class" => "mws-form", "type" => "file")); ?>


                <?php
                echo $this->Form->input('id');
                echo $this->Form->input('body', array("div" => "mws-form-row", "type" => "textarea", "class" => "", "between" => '<div class="mws-form-item large">')) . "</div>";

                echo "
                    <div class='q-choices many-container'>
                    <ul class='many'>";

                echo "<li><span class='remove-option mws-ic-16 ic-cross' onclick='remove_option(this)'></span>";
                echo $this->Form->input('QuestionChoice.0.body', array("div" => "e_right", "class" => " span3", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>";
                echo $this->Form->input('QuestionChoice.0.points', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>";
                echo '<div class="clear"></div></li>';


                echo "<li><span class='remove-option mws-ic-16 ic-cross' onclick='remove_option(this)'></span>" .
                $this->Form->input('image', array("div" => "e_right", "class" => " span3", "after" => '<span class="add-on">' . __("Option") . '</span>', "between" => '<div class="input-append">', "label" => false)) . "</div>"
                . $this->Form->input('image', array("div" => "e_right input-file-width", "type" => "file", "class" => "", "between" => '<div class="mws-form-item ">', "label" => false)) . "</div>"
                . $this->Form->input('image', array("div" => "e_right", "after" => '<span class="add-on">' . __("Grade") . '</span>', "class" => " span1 s2", "value" => 0, "between" => '<div class="input-append">', "label" => false)) . "</div>"
                . '<div class="clear"></div></li>';

                echo '</ul><div class="clear"></div><a class="add-option mws-ic-16 ic-add add" >Add onther option</a></div>'
                ?>

                <div class="mws-button-row">
                    <input type="submit" class="mws-button orange mws-i-24 i-check large" value="<?php echo __('Submit'); ?>">
                </div>
                <?php echo $this->Form->end(); ?>

            </div>


            <div class="clear"> </div>
        </div>
    </div>


</div>

<script>
    $(function() { 
        //----- Add data to every container have many child   ------------//
        $('ul.many').each(function(){
            $(this).data('counter', $(this).children().length)
            $(this).data('template', 
            $('li:first', $(this))
            .clone(true)
            .find(':input')
            .removeAttr('value')
            .end()
            .find('.fileupload-new img').remove()
            .end()


        );
         
        });
        
        $('.quistion-list > div').each(function(){
            $("#questions_types > ."+$(this).attr("class"))
            .data('template', 
            $(this)
            .clone(true) 
        );
        });
        
         
        //---------------------------------------------------
        
        if($.fn.customFileInput) {
            $("input[type='file']").customFileInput();
        }
        for (var n in opts)
            $("." + n).spinner(opts[n]);
        
           
        $(document).on('click','.many-container a.add',function(){
            var link = this;
            $(this).html(function(i, h){
                return h.replace(/^Add New/i, 'Add Another');
            });
            var counter = $('ul.many', $(link).parents('div.many-container')).data('counter');
            
            $('ul.many', $(link).parents('div.many-container')).data('counter', counter + 1);
            
            $('ul.many', $(link).parents('div.many-container')).data('template')
            .clone(true)
            .appendTo($('ul.many', $(this).parents('div.many-container')))
            .hide()
            .find('*')
            .attr('for', function(index, attr){
                if(!attr) return ;
                return attr.replace(/(.*?)(\d+)(.*?)/, "$1" +  counter  + "$3") ; 
            })
            .attr('id', function(index, attr){
                if(!attr) return ;
                return attr.replace(/(.*?)(\d+)(.*?)/, "$1" + counter + "$3") ; 
            })
            .attr('name', function(index, attr){
                if(!attr) return ;
                return attr.replace(/data\[(.*?)\]\[(\d+)\]\[(.*?)\]/, "data[$1][" +  counter  + "][$3]") ; 
            })
            .end()
            .slideDown(300)
            
            $('ul.many li:last', $(link).parents('div.many-container')).find(".s2").spinner(opts["s2"]); 
            $('ul.many li:last', $(link).parents('div.many-container')).find(".s1").spinner(opts["s1"]); 
            $('ul.many li:last', $(link).parents('div.many-container')).find("input[type='file']").customFileInput();
            
            return false;
        });
        $("#sortable" ).droppable({ 
           
            drop: function(event, ui ){
                if(ui.draggable.hasClass("drage_")){
                    ui.draggable.html($("#questions_types > ."+ui.draggable.attr("q"))
                    .data('template').clone(true)); 
                    ui.draggable.removeClass("drage_"); 
                    ui.draggable.find(".s2").spinner(opts["s2"]);
                    ui.draggable.find(".s1").spinner(opts["s1"]); 
                    ui.draggable.find("input[type='file']").customFileInput();
                    //  ui.draggable.effect( "bounce", "slow",400);
                    ui.draggable.find(".mws-form-inline").effect( "highlight",{"color":"#FFFF00"},2000); 
                    setTimeout(function(){$("textarea").ckeditor() ;},1000);
                }
            }
        }).sortable({
            handle: ".q-header1",
            revert: true,
            placeholder:"placeholder"
        });
        
        $( ".drage_" ).draggable({
            connectToSortable: "#sortable",
            helper: "clone",
            revert: "invalid"
        }); 
 

    });
    function remove_option(ele){
        if(confirm("Are you sure you want delete?"))
            $(ele).parent().slideUp(500, function(){
                $(this).remove();
            })
        
    }
    
</script>
<?php echo $this->Form->enableEditors('textarea'); ?>